package com.wancaijinfu.ui.index2;



import com.wancaijinfu.actitvity.R;
import com.wancaijinfu.constant.Params;
import com.wancaijinfu.constant.Url;
import com.wancaijinfu.javabean.AccountLog;
import com.wancaijinfu.javabean.UserData;
import com.wancaijinfu.parse.AccountLogParse;
import com.wancaijinfu.widget.MActionBar;
import com.wancaijinfu.widget.PullListBaseFragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class AccountContextFragment extends PullListBaseFragment {
	public static enum PINGDAO {
		CHONGZHI,TIXIAN,SHOUZHI,HONGBAO,TOUZI
	}
	
	public static final String CHONGZHI = "recharge";
	public static final String TIXIAN = "cash";
	public static final String SHOUZHI = "*";
	public static final String HONGBAO = "red_paper";
	public static final String TOUZI = "tender";
	private PINGDAO category;
	
	public static AccountContextFragment newInstantce(PINGDAO category) {
		AccountContextFragment fragment = new AccountContextFragment();
	
		Bundle bundle = new Bundle();
		bundle.putSerializable("PINGDAO", category);
		fragment.setArguments(bundle);
		
		
		
		return fragment;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		category = (PINGDAO) getArguments().getSerializable("PINGDAO");
	}
	
	@Override
	public void setMTitle(MActionBar actionBar) {
		actionBar.setDiabled();
	}

	
	@Override
	public void getUIData() {
		//Log.e("getingdata", "datas");
		String type;
		switch (category) {
			case CHONGZHI:
			type=CHONGZHI;
			break;
			case TIXIAN:
				type=TIXIAN;
			break;
			case SHOUZHI:
				type=SHOUZHI;
				break;
			case HONGBAO:
				type=HONGBAO;
				break;
			default:
			type=TOUZI;
			break;
		}
		
		Params params = Params.getInstance().add("type", type);
		String requestURL = Url.getAddress(Url.ACCOUNTLOG);
			getNetData(requestURL, params, new AccountLogParse());
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	static class ViewHolder {
		public TextView username;
		public TextView money;
		public TextView time;
		public View viewtop;
		public View viewfoot;
	}

	@Override
	public View bindViewItem(int position, View convertView, ViewGroup parent,
			Object object) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(getActivity()).inflate(
					R.layout.record_item, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.username = (TextView)convertView.findViewById(R.id.username);
			viewHolder.time = (TextView)convertView.findViewById(R.id.time);
			viewHolder.money = (TextView)convertView.findViewById(R.id.money);
			viewHolder.viewtop = convertView.findViewById(R.id.line1);
			viewHolder.viewfoot = convertView.findViewById(R.id.line2);
			
			convertView.setTag(viewHolder);
		} else {	
			viewHolder = (ViewHolder) convertView.getTag();
		}
		final AccountLog data = (AccountLog) object;
		viewHolder.time.setText(data.addtime);
//		item.id=newObj.getString("id");
//		item.money=newObj.getDouble("money");
//		item.type=newObj.getString("type");
//		item.addtime=newObj.getString("addtime");
		
		
//		viewHolder.time.setText(data.addtime);
		viewHolder.money.setText(data.money+"");
		
		viewHolder.username.setText(UserData.getInstance().name);
		if(data.status.equals("-1")){
			viewHolder.viewtop.setVisibility(View.INVISIBLE);
		}else if(data.status.equals("1")){
			viewHolder.viewfoot.setVisibility(View.INVISIBLE);
		}else {
			viewHolder.viewtop.setVisibility(View.VISIBLE);
			viewHolder.viewfoot.setVisibility(View.VISIBLE);
		}
		
		return convertView;
	}

	

	
	

}
